//
//  HNSH_MyTeamCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/28.
//

#import "HNSH_MyTeamCell.h"

@interface HNSH_MyTeamCell ()
/* bgView */
@property(nonatomic, strong) UIView *bgView;

/* 图片 */
@property(nonatomic, strong) UIImageView *icon;
/* vip图片 */
@property(nonatomic, strong) UIImageView *vipIcon;

/* 标题 */
@property(nonatomic, strong) UILabel *titleLabel;
/* 团队活跃度：10.00 */
@property(nonatomic, strong) UILabel *hydLabel;
/* 团队总数：133 */
@property(nonatomic, strong) UILabel *zsLabel;
/* phone */
@property(nonatomic, strong) UILabel *phoneLabel;
/* status */
@property(nonatomic, strong) UILabel *statusLabel;
/* timeLabel */
@property(nonatomic, strong) UILabel *timeLabel;

/* lineView */
@property (nonatomic, strong) UIView *lineView;
@end

@implementation HNSH_MyTeamCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor appBGColor];
        self.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_MyTeamListModel *)model {
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
    [self.vipIcon sd_setImageWithURL:[NSURL URLWithString:model.level_icon]];
    self.titleLabel.text = model.phone;
    self.hydLabel.text = [NSString stringWithFormat:@"团队活跃度：%.2f",[model.active_value doubleValue]];
    self.zsLabel.text = [NSString stringWithFormat:@"团队总数：%ld",model.team_count];
    self.phoneLabel.text = [NSString stringWithFormat:@"%@",model.phone];
    
    self.statusLabel.backgroundColor = model.certify_status == 1 ? [UIColor appGreenColor] : [UIColor appGrayLabelColor];
    self.statusLabel.text = model.certify_status == 1 ? @"已认证" : @"未认证";
    self.timeLabel.text = [NSString stringWithFormat:@"注册时间：%@",model.create_time];
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}


- (void)addAllViews {
    self.contentView.backgroundColor = [UIColor appBGColor];
    
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.icon];
//    [self.bgView addSubview:self.vipIcon];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.hydLabel];
    [self.bgView addSubview:self.zsLabel];
    [self.bgView addSubview:self.phoneLabel];
    [self.bgView addSubview:self.statusLabel];
    [self.bgView addSubview:self.timeLabel];
    [self.bgView addSubview:self.lineView];
}

- (void)addAllLayout {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
    }];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(15);
        make.width.height.mas_equalTo(44);
    }];
    
//    [self.vipIcon mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(45);
//        make.top.mas_equalTo(2);
//        make.width.mas_equalTo(45);
//        make.height.mas_equalTo(14);
//    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.icon.mas_right).offset(12);
        make.top.equalTo(self.icon.mas_top).offset(0);
        make.height.mas_equalTo(20);
    }];
    
    [self.hydLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(17);
    }];
    
    [self.zsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.hydLabel.mas_bottom).offset(2);
        make.height.mas_equalTo(17);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.zsLabel.mas_bottom).offset(2);
        make.height.mas_equalTo(17);
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
        make.height.mas_equalTo(17);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self.hydLabel.mas_centerY);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(45);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
    }];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_home_zixun"]];
        _icon.contentMode = UIViewContentModeScaleAspectFill;
        _icon.layer.cornerRadius = 22;
        _icon.layer.masksToBounds = YES;
    }
    return _icon;
}

- (UIImageView *)vipIcon {
    if (!_vipIcon) {
        _vipIcon = [[UIImageView alloc]init];
    }
    return _vipIcon;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"";
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)hydLabel {
    if (!_hydLabel) {
        _hydLabel = [[UILabel alloc]init];
        _hydLabel.text = @"";
        _hydLabel.textColor = [UIColor appGrayLabelColor];
        _hydLabel.font = [UIFont systemFontOfSize:12];
    }
    return _hydLabel;
}

- (UILabel *)zsLabel {
    if (!_zsLabel) {
        _zsLabel = [[UILabel alloc]init];
        _zsLabel.text = @"";
        _zsLabel.textColor = [UIColor appGrayLabelColor];
        _zsLabel.font = [UIFont systemFontOfSize:12];
    }
    return _zsLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc]init];
        _phoneLabel.text = @"";
        _phoneLabel.textColor = [UIColor appGrayLabelColor];
        _phoneLabel.font = [UIFont systemFontOfSize:12];
    }
    return _phoneLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.text = @"";
        _timeLabel.textColor = [UIColor appGrayLabelColor];
        _timeLabel.font = [UIFont systemFontOfSize:12];
    }
    return _timeLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc]init];
        _statusLabel.text = @"已认证";
        _statusLabel.textColor = [UIColor appWhiteLabelColor];
        _statusLabel.font = [UIFont systemFontOfSize:11];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.backgroundColor = [UIColor appGreenColor];
        _statusLabel.layer.cornerRadius = 8.0f;
        _statusLabel.layer.masksToBounds = YES;
    }
    return _statusLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F6"];
    }
    return _lineView;
}

@end
